$(function(){
	//showMenuPushList();
	//showUnusedMenuPushList();
});

/**
 * 显示推送常用菜单
 */
function showMenuPushList(){
	
	$.ajax({
		url:CUSTOM_SERVICE_URL + "smartMenuPush/findCustomMenuPushList",
		type:"GET",
		dataType:"json",
		success:function(r){
			if(r.body != null){
				
				var ul = $("<ul/>");
				
				for(var i=0;i<r.body.length;i++){
					
					var li = $("<li/>");
					var checkbox = $("<input/>");
					var label = $("<label/>");
					
					checkbox.attr({
						"type":"checkbox",
						"value":r.body[i].functionName,
						"name":"addMenuCode",
						"functionCode":r.body[i].functionCode
					});
					
					li.append(checkbox);
					label.html(r.body[i].functionName);
					li.append(label);
					ul.append(li);
				}
				
				$("#menuPushList").append(ul);
			}
		}
	});
}

/**
 * 显示推送非常用菜单
 */
function showUnusedMenuPushList(){
	
	$.ajax({
		url:CUSTOM_SERVICE_URL + "smartMenuPush/findUnusedCustomMenu",
		type:"GET",
		dataType:"json",
		success:function(r){
			if(r.body != null){
				
				var ul = $("<ul/>");
				
				for(var i=0;i<r.body.length;i++){
					
					var li = $("<li/>");
					var checkbox = $("<input/>");
					var label = $("<label/>");
					
					checkbox.attr({
						"type":"checkbox",
						"value":r.body[i].functionName,
						"name":"deleteMenuCode",
						"functionCode":r.body[i].functionCode,
						"checked":true
					});
					
					li.append(checkbox);
					label.html(r.body[i].functionName);
					li.append(label);
					ul.append(li);
				}
				
				$("#unusedMenuPushList").append(ul);
			}
		}
	});
}

/**
 * 批量添加或者删除信息
 */
function batchSubimt(){
	
	var addMenuCode = $("#menuPushList input[type='checkbox'][name='addMenuCode']:checked");
	var deleteMenuCode = $("#unusedMenuPushList input[type='checkbox'][name='deleteMenuCode']:checked");
	
	if(addMenuCode != null && addMenuCode.length > 0){
		
		var addMenuCodeList = new Array();
		if(addMenuCode != null){
			for(var i=0;i<addMenuCode.length;i++){
				addMenuCodeList[i] = $(addMenuCode[i]).attr("functionCode");
			}
		}
		
		$.ajax({
			url:CUSTOM_SERVICE_URL + "smartMenuPush/batchAddCustomMenu",
			data:JSON.stringify(addMenuCodeList),
			type:"POST",
			contentType :'application/json;charset=utf-8',
			dataType:"json",
			success:function(r){
				if(r.body != null){
					findUserCustomMenuList();
				}
			}
		});
	}
	
	if(deleteMenuCode != null  && deleteMenuCode.length > 0){
		
		var deleteMenuCodeList = new Array();
		if(deleteMenuCode != null){
			for(var i=0;i<deleteMenuCode.length;i++){
				deleteMenuCodeList[i] = $(deleteMenuCode[i]).attr("functionCode");
			}
		}
		
		$.ajax({
			url:CUSTOM_SERVICE_URL + "smartMenuPush/batchRemoveCustomMenu",
			data:JSON.stringify(deleteMenuCodeList),
			type:"POST",
			dataType:"json",
			contentType : 'application/json;charset=utf-8',
			success:function(r){
				if(r.body != null){
					findUserCustomMenuList();
				}
			}
		});
	}
}

/**
 * 关闭窗口
 */
function closePushWin(){
	$("#smartMenuPushDiv").hide();
}
